package com.qf.flash.mvp.presenter;

import com.hyphenate.easeui.utils.ChatUserCacheMgr;
import com.qf.dblib.dao.entity.ChatUser;
import com.qf.dblib.dao.entity.UserInfo;
import com.qf.dblib.dao.impl.UserMgr;
import com.qf.flash.http.HttpManager;
import com.qf.flash.mvp.contract.UserInfoContract;
import com.qf.flashlib.base.BasePresenter;
import com.qf.flashlib.base.BaseSubscriber;
import com.qf.flashlib.util.RxUtils;

/**
 * 描述: 评论列表
 * 2020/3/24 14:20
 */
public class UserInfoPresenter extends BasePresenter<UserInfoContract.View> implements UserInfoContract.Presenter {

    @Override
    public void getUserInfo(String userId) {
        addSubscription(HttpManager.getInstance().getGsonHttpApi()
                .USER_INFO(userId, UserMgr.getInstance().getLoginUser().getUid())
                .compose(RxUtils.handleResult())
                .compose(RxUtils.io_main())
                .subscribeWith(new BaseSubscriber<UserInfo>(mRootView, false) {
                    @Override
                    public void onSuccess(UserInfo userInfo) {
                        if (userInfo != null) {
                            ChatUser chatUser = new ChatUser();
                            chatUser.setUsername(userInfo.getName());
                            chatUser.setAvatar(userInfo.getPhoto());
                            chatUser.setNick(userInfo.getName());
                            chatUser.setUid(userInfo.getUid());
                            ChatUserCacheMgr.getInstance().saveUser(chatUser);
                            mRootView.setUserInfo(userInfo);
                        }
                    }
                })
        );
    }
}
